package leetcode.tree;

import java.util.Arrays;
import java.util.stream.Collectors;

import datastructure.binarytree.TreeNode;

public class LeetCode114Traverse {

    // 虚拟头节点，dummy.right 就是结果
    TreeNode dummyHead = new TreeNode(-1);
    // 用来构建链表的指针
    TreeNode p = dummyHead;
    TreeNode flatten(TreeNode root) {
        traverse(root);
        return dummyHead.right;
    }
    private void traverse(TreeNode root) {
        if (root == null) {
            return;
        }
        p.right = new TreeNode(root.val);
        p = p.right;
        traverse(root.left);
        traverse(root.right);
        System.arraycopy(root, 0, root, 0, 0);
        Arrays.stream(new int[10]).boxed().collect(Collectors.toList());
    }



    
}
